using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using NUnit.Mocks;

namespace Hawkeye.Specs
{
  [TestFixture]
  public class Story1
  {
    [TearDown]
    public void After_each()
    {
      engine.Run();
      service.Verify();
    }
    /*
     * As a developer
     * In order to see that Hawkeye hasn't "hanged",
     * I want some information printed on the console during analyzis!
     */
    [Test]
    public void Example1()
    {
      Given_some_input();
      The_first_thing_shown_is("C# Hawkeye");
    }

    [Test,Ignore]
    public void Example2()
    {
      Given_inputpath("somepath");
      And_path_content("somepath",
        "file1.cs", "class T {}",
        "file2.cs", "class B {}");
      Should_display(
        "Looking for classes...",
        "Found 2 classes.");
    }

    private void Should_display(params string[] lines)
    {
      foreach (string line in lines)
        service.Expect("WriteLine", line);
    }

    Dictionary<string, Dictionary<string, string>> fs = new Dictionary<string, Dictionary<string, string>>();
    private void And_path_content(string path, params string[] content)
    {
      fs[path] = new Dictionary<string,string>();
      for (int i = 0; i < content.Length; i += 2)
        fs[path][content[i]] = content[i + 1];
    }

    private void Given_inputpath(string path)
    {
    }

    private void The_first_thing_shown_is(string line)
    {
      service.Expect("WriteLine", line);
    }

    public class HawkeyeEngine {
      public interface IService
      {
        void WriteLine(string line);
      }

      IService service;

      public HawkeyeEngine(IService service)
      {
        this.service = service;
      }

      public void Run()
      {
        service.WriteLine("C# Hawkeye");
      }
    }

    HawkeyeEngine engine;
    DynamicMock service;
    private void Given_some_input()
    {
      service = new DynamicMock(typeof(HawkeyeEngine.IService));
      engine = new HawkeyeEngine((HawkeyeEngine.IService)service.MockInstance);
    }
  }
}
